package com.dyna.factory;

import com.dyna.handler.RedisDelayMsgHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * redis延时消息处理工厂
 */
@Component
public class RedisDelayMsgHandlerFactory {

    public final static Map<Integer, RedisDelayMsgHandler> handlerMap = new HashMap<>();

    @Autowired
    public RedisDelayMsgHandlerFactory(List<RedisDelayMsgHandler> handlers) {
        for (RedisDelayMsgHandler handler : handlers) {
            // 假设可以根据handler的getClass方法获取到对应的类型名称
            handlerMap.put(handler.getDelayMsgType(), handler);
        }
    }

    public RedisDelayMsgHandler getHandler(Integer type) {
        return handlerMap.get(type);
    }

}